home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / dllistb.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-14  |  3.5 KB  |  113 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- // 
  5. // C++ Source Code File Name: dllistb.cpp
  6. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  7. // Produced By: Doug Gaer
  8. // File Creation Date: 12/29/1996
  9. // Date Last Modified: 03/15/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ------------- Program Description and Details ------------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. Base classes for doubly linked list implementations. The
  32. DNodeBase class and the DLListBase class separates the nodes
  33. from the data stored in the list by storing pointer to the
  34. data. Classes derived from these base classes can deal with
  35. any type of node data.
  36. */
  37. // ----------------------------------------------------------- // 
  38. #include "dllistb.h"
  39.  
  40. void DNodeBase::InsertBefore(DNodeBase *Node)
  41. {
  42.   Node->Prior = Prior;
  43.   Prior->Next = Node;
  44.   Node->Next = this;
  45.   Prior = Node;
  46. }
  47.  
  48. void DNodeBase::InsertAfter(DNodeBase *Node)
  49. {
  50.   Node->Next = Next;
  51.   Next->Prior = Node;
  52.   Node->Prior = this;
  53.   Next = Node;
  54. }
  55.  
  56. DNodeBase *DNodeBase::Rmv()
  57. {
  58.   Prior->Next = Next;
  59.   Next->Prior = Prior;
  60.   return this;
  61. }
  62.  
  63. DLListBase::~DLListBase()
  64. {
  65.   // Destructor provided for virtuality
  66. }
  67.  
  68. void DLListBase::MakeEmpty()
  69. {
  70.   SelfRef(); 
  71. }
  72.  
  73. void DLListBase::Clear()
  74. {
  75.   DNodeBase *Node = Next;
  76.   while(!IsHeader(Node)) {
  77.     DNodeBase *NextNode = Node->Next;
  78.     FreeNode(Node); // Must be defined in derived  classes
  79.     Node = NextNode;
  80.   }
  81.   MakeEmpty();
  82. }
  83.  
  84. DNodeBase *DLListBase::Rmv(DNodeBase *Node)
  85. {
  86.   if(Node == this) return 0; // Return null if Node is the header
  87.   return Node->Rmv(); // Remove and return Node pointer
  88. }
  89.  
  90. int DLListBase::Copy(const DLListBase &List)
  91. {
  92.   if(&List == this) return 1; // Already its own copy
  93.   Clear(); // Clear current nodes from this list
  94.   return Cat(List); // 1 if successful, 0 if fails
  95. }
  96.  
  97. int DLListBase::Cat(const DLListBase &List)
  98. {
  99.   if(this == &List) return 0; // Do not append list onto itself
  100.   const DNodeBase *ptr = List.Next;
  101.   while(!List.IsHeader(ptr)) { // For all nodes in List
  102.     DNodeBase *Node = DupNode(ptr);
  103.     if(Node == 0) return 0; // Incomplete copy made
  104.     AttachToBack(Node);
  105.     ptr = ptr->Next;
  106.   }
  107.   return 1; // Successful concatenation
  108. }    
  109. // ----------------------------------------------------------- //
  110. // ------------------------------- //
  111. // --------- End of File --------- //
  112. // ------------------------------- //
  113.